package cvc.framework.controller;

import cvc.framework.entity.Camera;
import cvc.framework.result.RestMessage;
import cvc.framework.result.RestResult;
import cvc.framework.service.CameraService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/Camera")
public class CameraController {

    @Autowired
    private CameraService cameraService;

    //获取摄像头参数
    @RequestMapping("/getCamera")
    @ResponseBody
    public RestResult getFrontEnd() {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = cameraService.getCamera();
        return res;
    }

    //修改参数
    @RequestMapping("/updateCamera")
    @ResponseBody
    public RestResult updateCamera(Camera camera) {
        RestResult res = new RestResult();
        res.message = new RestMessage();
        res.message.data = cameraService.updateCamera(camera);
        return res;
    }

    //获取识别图片地址
    @RequestMapping("/getImgPath")
    @ResponseBody
    public RestResult getImgPath() {
        RestResult res = new RestResult();
        try {
            res.message = new RestMessage();
            res.message.data = cameraService.getImgPath();
        } catch (Exception e) {
            res.state = 1;
            res.error = e.toString();
        }
        return res;
    }
}
